<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
  <style>
    #app {
      display: flex;
    }

    .nav {
      width: 300px;
      margin: 10px;
      border: 1px solid lightgreen;
      font-size: 24px;
      height: 800px;
    }

    .content {
      margin: 10px;
      border: 1px solid #666;
      height: 800px;
      width: 900px;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="nav">
      <router-link to="/teacher">教师管理</router-link><br>
      <router-link to="/student">学生管理</router-link><br>
      <router-link to="/logistics">后勤管理</router-link>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
  <script>
    // 1.定义组件
    let comA = {
      template: `
        <div>
          教师管理
        </div>
      `
    }
    let comB = {
      template: `
        <div>
          学生管理
          <div>
            <button @click="clickHandler">成绩管理</button>
            <button @click="clickHandler">学籍管理</button>
          </div>
          <div>
            <router-view></router-view>  
          </div>
        </div>
      `,
      methods: {
        clickHandler(e) {
          if (e.target.innerText == '成绩管理') {
            this.$router.push({
              path: '/student/grade',
              query: { name: 'zhangsan', age: 12 }
            })
          } else {
            this.$router.push({
              name: 'reg',
              params: { name: 'lisi', gender: 'male' }
            })
          }
        }
      }
    }
    let comC = {
      template: `
        <div>
          后勤管理
        </div>
      `
    }
    let comGrade = {
      template: `
        <div>
          学生的成绩表格
        </div>
      `,
      created() {
        console.log(this.$route.query);
      }
    }
    let comRegister = {
      template: `
        <div>
          学生的学籍表格
          <button @click="goBackHandler">返回</button>
        </div>
      `,
      created() {
        console.log(this.$route.params);
      },
      methods: {
        goBackHandler() {
          this.$router.go(-1)
        }
      }
    }
    // 2.定义路由
    let router = new VueRouter({
      mode: 'history',  // 路由模式
      routes: [
        { path: '/teacher', component: comA },
        {
          path: '/student',
          component: comB,
          // redirect: '/student/grade',
          children: [
            { path: 'grade', component: comGrade },
            { path: 'register', component: comRegister, name: 'reg' },
          ]
        },
        { path: '/logistics', component: comC },
      ]
    })

    let vm = new Vue({
      el: "#app",
      data: {

      },
      methods: {

      },
      created() {

      },
      // 3.注册路由
      router
    })
  </script>
</body>

</html>